package com.zyk.leetcode;

/**
 * @author zhangsan
 * @date 2021/4/25 8:56
 */
public class C7 {


    public static int reverse(int x) {
        int rev = 0;
        while (x != 0) {
            int pop = x % 10;   // 个 十 百 千 万
            x /= 10;
            if (rev > Integer.MAX_VALUE/10 || (rev == Integer.MAX_VALUE / 10 && pop > 7)) return 0;
            if (rev < Integer.MIN_VALUE/10 || (rev == Integer.MIN_VALUE / 10 && pop < -8)) return 0;
            rev = rev * 10 + pop;   // 个变成十     十成百     百成千
        }
        return rev;
    }

    public static void main(String[] args) {
        int x = Integer.MAX_VALUE;
        System.out.println(x);
        System.out.println(reverse(x));
    }

}
